package com.ph.exception;

import java.lang.reflect.Method;

import org.springframework.aop.ThrowsAdvice;

public class ExceptionHandler implements ThrowsAdvice {
	public void afterThrowing(Method method, Object[] args, Object target,
			Throwable subclass) throws Throwable {		
		if(subclass.getMessage().contains("Duplicate")){
			throw new PHException("不能输入重复数据");
		}
		if(subclass.getMessage().contains("foreign key")){
			throw new PHException("要删除的数据在其他地方被用到，不能删除，请确认后操作");
		}
		
		if(subclass.getMessage().contains("NullPoint")){
			throw new PHException("空指针错误");
		}
		
//		将收集到的所有Exception信息在这里做分类，如上面所示
//		if(subclass.getMessage().contains("...")){
//			throw new PHException("...");
//		}
	}

}